﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using VPN.Manage;
using VPN.DataContext;

namespace VPNNew.UserContorls
{
    public partial class POList : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                gvPO.DataSource = POManage.GetPOList(SearchArg, Pager1);
                gvPO.DataBind();
            }
        }

        public POSearchArg SearchArg
        {
            get
            {
                POSearchArg arg = new POSearchArg(Request.QueryString["q"]);
                if (!Page.User.IsInRole("Administrators"))
                    arg.UserName = Page.User.Identity.Name;
                return arg;
            }

        }

        protected void Pager1_PageIndexChanged(object sender, SWAS.Web.UI.Controls.PageIndexChangeArgs e)
        {
            gvPO.DataSource = POManage.GetPOList(SearchArg, Pager1);
            gvPO.DataBind();
        }

        protected void gvPO_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                PO po = (PO)e.Row.DataItem;
                if (po.Status != (int)POStatus.NotPaid)
                {
                    e.Row.Cells[3].Controls.Clear();
                    e.Row.Cells[4].Controls.Clear();
                }
            }
        }

        protected void gvPO_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            POManage.Cancel(gvPO.DataKeys[e.RowIndex][0].ToString());
            gvPO.DataSource = POManage.GetPOList(SearchArg, Pager1);
            gvPO.DataBind();
        }




    }
}